package com.hanxiang.hankol.help

import android.Manifest
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import android.widget.PopupWindow
import com.alibaba.android.arouter.facade.annotation.Route
import com.baselibrary.Constants
import com.baselibrary.permission.PermissionCollection
import com.baselibrary.permission.PermissionsUtils
import com.baselibrary.permission.callback.PermissionsCall
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.AppManager
import com.baselibrary.utils.DoubleClickHelper
import com.baselibrary.utils.SpUtils
import com.baselibrary.utils.ToastUtils
import com.hankol.community.arouter.CommunityHelp
import com.hankol.message.PopupUtil
import com.hanxiang.hankol.common.WindowAddCommentActivity
import com.media.image.ImageModel
import com.media.publish.service.UploadMediaService
import com.media.revision.RevisionMediaActivity
import com.okhttp.comment.CommentConstant
import com.hanxiang.hankol.common.JuBaoOneActivity

//mall 子moudle 调用 app
@Route(path = ActivityRouter.COMMUNITY.COMMUNITY_HELP)
class CommunityHelpIml : CommunityHelp {

    override fun openCommentActivity(activity: Activity, type: Int, videoId: Int, exisContent: String, name: String, isShowReply: Boolean, code: Int) {
        val bundle = Bundle()
        //type:评论类型 1评论的评论 4文章评论 5产品评论 6动态评论 7专栏评论 8话题评论 9话题动态评论 10 讲坛评论 11 课程评论
        bundle.putInt("type", type)
        bundle.putInt("typeId", videoId)
        bundle.putString("content", if (exisContent == CommentConstant.COMMENT_DEF_CONTENT_VERSION_1_COPY
                || exisContent == CommentConstant.COMMENT_DEF_CONTENT_VERSION_1
                || exisContent == CommentConstant.COMMENT_DEF_CONTENT_VERSION_2) "" else exisContent)
        bundle.putBoolean("isShowReply", isShowReply)
        bundle.putSerializable("title", name)
        val mIntent = Intent(activity, WindowAddCommentActivity::class.java)
        mIntent.putExtras(bundle)
        activity.startActivityForResult(mIntent, code) //此处的requestCode应与下面结果处理函中调用的requestCode一致

    }

    override fun getJuBaoOneActivity(): Class<*> {
        return JuBaoOneActivity::class.java
    }

    override fun showCommentPop(activity: Activity, view: View, tagView: View, gravity: Int): PopupWindow {
        val mCommentViewPopup =
                PopupUtil.showPopwindow(activity, view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
        mCommentViewPopup.showAtLocation(tagView, gravity, 0, 0)
        setBackgroundAlpha(activity) //设置屏幕透明度
        return mCommentViewPopup
    }

    override fun setBackgroundAlpha(activity: Activity) {
        PopupUtil.setBackgroundAlpha(activity, 0.5f) //设置屏幕透明度
    }


    override fun goPublish(activity: Activity) {
        if (!DoubleClickHelper.isOnDoubleClick()) {
            PermissionsUtils.getInstance().chekPermissions(activity,
                    PermissionCollection.CUSTOM.addPermissionList(Manifest.permission.WRITE_EXTERNAL_STORAGE,
                            Manifest.permission.RECORD_AUDIO, Manifest.permission.CAMERA), object : PermissionsCall() {
                override fun permissionsPass() {
                    if (!SpUtils.getInstance().isLogin) {
                        AppManager.getAppManager().openLoginPage()
                        return
                    }
                    if (UploadMediaService.isPublishing) {
                        ToastUtils.showShort(activity, "有发布任务未完成，请稍后再试")
                    } else {
                        val intent = Intent(activity, RevisionMediaActivity::class.java)
                        intent.putExtra("type", ImageModel.TYPE_ALL)
                        intent.putExtra("maxstr", Constants.PUBLISH_IMG_MAX)
                        activity.startActivity(intent)
                    }
                }
            })
        }
    }


    override fun goLiveDetail(activity: Activity, id: Int) {
//        val intent = Intent(activity, LivePlayerActivity::class.java)
//        intent.putExtra("id", id)
//        activity.startActivity(intent)
    }

    override fun goLiveInfo(activity: Activity, id: Int) {
//        val intent = Intent(activity, LiveInfoActivity::class.java)
//        intent.putExtra("id", id)
//        activity.startActivity(intent)
    }

    override fun getPublishStatus():Boolean {
        return UploadMediaService.isPublishing
    }


    override fun init(context: Context?) {
    }

}